package WeekOne;

import java.util.Scanner;

/**
 * @Author @fiber-cloud
 * @Date 2025/10/18 10:23
 */
public class DAY04 {
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        //n变成斐波那契数，最少一定是与周围两个数相关的
        int f1 = 0;
        int f2 = 1;
        while (n > f2){//退出条件是n<=f2，此时，f1<n<=f2
            int f3 = f2 + f1;
            f1 = f2;
            f2 = f3;
        }
        int min = Math.min(n-f1,f2-n);
        System.out.println(min);
    }


    public static void main(String[] args) {
        //求杨辉三角的前n行
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[][] dp = new int[n+1][n+1];
        dp[1][1] = 1;

        for (int i = 2; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                //填充dp数组中的数字
                dp[i][j] = dp[i-1][j]+dp[i-1][j-1];
            }
        }


        //打印要求输出的杨辉三角
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i; j++) {


                StringBuffer ret = new StringBuffer();
                //对齐，格式化输出
                // 计算每个数字的字符串长度
                int len = Integer.toString(dp[i][j]).length();
                //在数字前加空格，使得每个数字占5个字符宽度
                for (int k = 0; k < 5-len; k++) {
                    ret.append(" ");
                }
                System.out.print(ret.toString()+dp[i][j]);
            }
            System.out.println();
        }
    }


    public boolean exist (String[] board, String word) {
        //board是一个String数组，要在其中找到word是否存在
        //先把String数组中的字符给分开
        char[][] chars = new char[board.length][board[0].length()];
        for (int i = 0; i < board.length; i++) {
            chars[i] = board[i].toCharArray();
        }

        //准备递归寻找
        for (int i = 0; i < board.length; i++) {
            for (int j = 0; j < board[0].length(); j++) {
                if (dfs(chars,word.toCharArray(),i,j,0)){
                    return true;
                }
            }
        }
        return false;
    }

    private boolean dfs(char[][] chars, char[] word, int i, int j, int k) {
        if (i >= chars.length || i<0 || j>= chars[0].length || j<0 || chars[i][j] != word[k]){
            return false;
        }
        if (k == word.length - 1){
            return true;
        }
        chars[i][j] = '\0';

        boolean res = dfs(chars,word,i+1,j,k+1)||dfs(chars,word,i-1,j,k+1)||
                dfs(chars,word,i,j+1,k+1)||dfs(chars,word,i,j-1,k+1);

        chars[i][j] = word[k];
        return res;
    }


}
